/**
 * 返利记录
 * Created by kefu on 2017/12/21.
 */

$(function(){
    //初始化日期控件
    $('#bt, #et').datetimepicker({
        language: 'zh-CN',
        format: 'yyyy-mm-dd',
        autoclose: true,
        minuteStep: 1,
        minView: "month"
    });
    loadDatas();
});

//加载玩家转账记录
function loadDatas(s){

    if(s=="search"){
        $("#page").val("");
    }

    //页码
    var page = $("#page").val();
    //一页显示的条数
    var pageSize = 40;
    //开始时间
    var begin = $("#begin_time").val();
    //结束时间
    var end = $("#end_time").val();
    //推广号
    var gameId = $("#gameId").val();

    //返利类型
    var type=$("#rebate_type").val();
    console.log(type)

    $.ajax({
        type: "post",
        data: {"page":page, "pageSize":pageSize, "begin":begin, "end":end, "gameId":gameId,"type":type},
        url: "../../../php/player/playerInfo/loadPlayerRebateRecord.php",
        beforeSend: function(){
            $("#load").css("display","block");
        },
        success: function(msg){
            $("#load").css("display","none");

            //表格数据
            var datas = msg.records;
            var html = "";
            if(datas.length == 0){
                html += "<tr><td colspan='7' align='center'>没查询到符合条件的数据~</td></tr>";
            }else{
                for(var i = 0; i<datas.length; i++){
                    html += "<tr>";
                    html += "<td>"+datas[i].rebate_id+"</td>";//订单号
                    var type;
                    if(datas[i].type == "1"){
                        type="银商转出返利";
                    }else if(datas[i].type == "2"){
                        type="客户转入返利";
                    }else if(datas[i].type == "3"){
                        type="银商每日流水返利";
                    }
                    html += "<td>"+type+"</td>";//注册IP
                    html += "<td>"+datas[i].amount+"</td>";//登录IP
                    var recv;
                    if(datas[i].is_recv==0){
                        recv="未接收";
                    }else if(datas[i].is_recv==1){
                        recv="已接收";
                    }
                    html += "<td>"+recv+"</td>";//购买数量
                    html += "<td>"+datas[i].create_time+"</td>";//获得金币
                    html += "<td>"+datas[i].recv_time+"</td>";//充值时间
                    html += "<td>"+datas[i].remark+"</td>";//充值类型

                    html += "</tr>";
                }
            }
            $("#databody").html(html);

            //分页数据
            var pageInfos = msg.pageInfo;
            //总条数
            var allCount = pageInfos[0].count;
            $("#count").html(allCount);
            //总页数
            var allPage = Math.ceil(allCount/pageSize);
            if(allPage==0){
                allPage = 1;
            }
            //当前页码
            var now = pageInfos[0].page;

            $("#page").val(now);
            $("#nowPage").html(now);
            $("#allPage").html(allPage);
            $("#pageIpu").val("");
        },error:function(msg){
            console.log('5')
        }
    });
}

//加载所有
function findAll(){
    $("#load").css("display","block");

    $("#reset").click();

    loadDatas('search');
}